using DocumentaWeb.Core;
using DocumentaWeb.Core.Messages;
using MbUnit.Framework;
using DocumentaWeb.Core.Services;
using Rhino.Mocks;

namespace DocumentaWeb.Tests.Unit.Services
{
	[TestFixture,FixtureCategory("Services")]
	public class ContratistaServiceTestFixture
	{
		private MockRepository mockery;
		private IContratista contratista;
		private IContratistaMapper mapper;
		private IContratistaRepository repository;
		

		[SetUp]
		public void SetUp()
		{
			mockery =new MockRepository();
			mapper = mockery.DynamicMock<IContratistaMapper>();
			contratista = mockery.DynamicMock<IContratista>();
			repository = mockery.DynamicMock<IContratistaRepository>();
		}


		[Test]
		public void Add_ShouldSaveContratista_AndBuildResponseWithSuccess()
		{
			IContratistaService service = new ContratistaService(mapper,repository);
			AddContratistaResponseDto response = service.AddContratista(new AddContratistaRequestDto());
			Assert.IsTrue(response.ContratistaAdded,"El Contratista no fue agregado");
		}

		[Test]
		public void Add_ShouldUseMapperForContratista()
		{
			AddContratistaRequestDto request=new AddContratistaRequestDto();
			IContratistaService service = new ContratistaService(mapper,repository);
			using(mockery.Record())
			{
				Expect.Call(mapper.MapFrom(request)).Return(contratista);
				repository.Save(contratista);
			}
			using(mockery.Playback())
			{
				service.AddContratista(request);
			}
		}
	}
}